package com.magold.io;

import java.io.FileNotFoundException;
import java.io.OutputStream;

import javax.xml.transform.TransformerException;

public interface XMLWriter extends XMLHelper {
	
	/**
	 * create a new document.
	 * 
	 * @throws IllegalStateException if last result hasn't been submitted.
	 */
	public void init() throws IllegalStateException;
	
			
	/**
	 * append a text node to current node.
	 * 
	 * @param content
	 * @param autoBack
	 */
	public void appendText(String content);
	
	/**
	 * set the value of specified attribute.
	 * This will change the original value.
	 * 
	 * @param attribName
	 * @param attribValue
	 * @param autoBack if true, current node will change to previous.
	 */
	public void setAttribute(String attribName, String attribValue);
	
	/**
	 * this will set current node to the new child node.
	 * 
	 * @param childName
	 */
	public void appendElement(String childName);
	
	/**
	 * write results to destfile.
	 * 
	 * @param out
	 * @return
	 * @throws FileNotFoundException if file create failed.
	 * @throws TransformerException if occur exception while transforming.
	 */
	public boolean submit(OutputStream out) throws FileNotFoundException, TransformerException;
	
	public void submitAsync(OutputStream out, XMLWriterListener listener);
	
	public static interface XMLWriterListener {
		
		public void onException(Exception e);
		
		public void onResult(boolean success);
	}
}
